﻿using System;


namespace ConsoleApp
{
     public class Circle:Shape,isValid
    {
        private double r;
        public Circle(int r)
        {
            
            this.r = r;
        }

        public override void draw()
        {
            Console.WriteLine("您画了一个半径为" + r + "的圆");

        }

        public override double culculateArea()
        {
           

            return Math.Round(Math.PI * r * r,2);

        }

        public  void isValid()
        {
            if (r <= 0)
            {
                Console.WriteLine("图形非法");

            }
            else
            {
                Console.WriteLine("合法");
            }
        }


       
    }
    public class Rectangle : Shape, isValid
    {
        private double len;
        private double wide;
        public Rectangle(double len,double wide)
        {
        this.len = len;
        this.wide = wide;
        }
        public override void draw()
        {
            Console.WriteLine("您画了一个长为" + len + "宽为" + wide + "的矩形");

        }

        public override double culculateArea()
        {


            return Math.Round(len * wide,2);

        }

        public void isValid()
        {
            if (len <= 0||wide<=0)
            {
                Console.WriteLine("图形非法");

            }
            else
            {
                Console.WriteLine("合法");
            }
        }


    }

    public class Square:Shape, isValid
    {
        double len;
        public Square(double len)
        {
            this.len = len;
        }

        public override void draw()
        {
            Console.WriteLine("您画了边长为" + len + "的正方形");

        }

        public override double culculateArea()
        {


            return Math.Round(len * len, 2);

        }

        public void isValid()
        {
            if (len <= 0 )
            {
                Console.WriteLine("图形非法");

            }
            else
            {
                Console.WriteLine("合法");
            }
        }
    }
    
}
